package cn.drew.org.controller;

import cn.drew.basic.utils.AjaxResult;
import cn.drew.basic.utils.PageList;
import cn.drew.org.domain.SystemDictionaryType;
import cn.drew.org.query.SystemDictionaryTypeQuery;
import cn.drew.org.service.SystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
public class SystemDictionaryTypeController {

    @Autowired
    private SystemDictionaryTypeService systemDictionaryTypeService;

    @GetMapping
    public List<SystemDictionaryType> findALl(){
        List<SystemDictionaryType> list = systemDictionaryTypeService.findAll();
        return list;
    }

    @GetMapping("/{id}")
    public SystemDictionaryType findById(@PathVariable("id") Long id){
        SystemDictionaryType systemDictionaryType = systemDictionaryTypeService.findById(id);
        return systemDictionaryType;
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryType systemDictionaryType){
        if(systemDictionaryType.getId() != null){
            systemDictionaryTypeService.update(systemDictionaryType);
        }else{
            systemDictionaryTypeService.add(systemDictionaryType);
        }

        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult Delete(@PathVariable("id") Long id){
        systemDictionaryTypeService.delete(id);
        System.out.println(id);
        return AjaxResult.success();
    }

    //    分页查询
    @PostMapping
    public PageList<SystemDictionaryType> queryByPage(@RequestBody SystemDictionaryTypeQuery systemDictionaryTypeQuery){
        PageList<SystemDictionaryType> pageList = systemDictionaryTypeService.queryByPage(systemDictionaryTypeQuery);
        return pageList;
    }

    //批量删除
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        systemDictionaryTypeService.patchDelete(ids);
        return AjaxResult.success();
    }

//    //无线级数
//    @GetMapping("/tree")
//    public List<SystemDictionaryType> tree(){
//        List<SystemDictionaryType> tree = systemDictionaryTypeService.tree();
//        System.out.println(tree);
//        return SystemDictionaryTypeService.tree();
//
//    }



}
